package com.example.customview.view

import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.util.AttributeSet
import android.view.View
import androidx.core.graphics.toColorInt
import com.sample.base.utils.dp

class CircleView(context: Context?, attrs: AttributeSet?) : View(context, attrs) {
    private val RADIUS = 100.dp
    private val PADDING = 50.dp
    private val paint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
        color = "#ff0000".toColorInt()
    }

    override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
        val size = PADDING + RADIUS * 2
        val width = resolveSize(size, widthMeasureSpec)
        val height = resolveSize(size, heightMeasureSpec)
        setMeasuredDimension(width, height)
    }

    override fun onDraw(canvas: Canvas) {
        canvas.drawCircle(
            (PADDING + RADIUS).toFloat(), (PADDING + RADIUS).toFloat(),
            RADIUS.toFloat(), paint
        )
    }
}